#!/bin/bash

# Looks for CD/DVD drives and then determine
# if there is at least ONE disc in the system's CDROM drives.

# Copyright (C) 2003-2006 IBM
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

. "$POUNDER_SRCDIR/libidecd.sh"

DRIVES_FOUND=`find_discs_with_media`
if [ "$DRIVES_FOUND" == "NONE 0" ]; then
        echo "[ide_cdrom_copy] No CD/DVD drives found. CD test will not build."
        exit 1;
fi

DEFAULT_MOUNT="$POUNDER_TMPDIR/cdmount"

# Ensure that our default mountpoint and destination dirs exist.
mkdir -p "$DEFAULT_MOUNT"

# How many discs can we find?
DISCS_FOUND=`find_discs_with_media | wc -l`
if [ $DISCS_FOUND -lt 1 ]; then
        echo -en "Examined "
        find_disc_devices | while read f; do
                echo -en "$f "
                eject "$f"
        done
        echo " and found no discs to test."
        echo "Please put a disc into the CD/DVD drive(s) and press ENTER."
        read garbage

        DISCS_FOUND=`find_discs_with_media | wc -l`
        if [ $DISCS_FOUND -lt 1 ]; then
                echo "Still can't find any discs.  CD test will probably not run."
                exit 0
        fi
fi

exit 0

